<template>
	<view>
		<view class="preview-body">
			<view class="list" v-for="(item,index) in dataList" :key="index">
				<view class="title"><text class="mast-text" v-if="item.must_status == 1">*</text>
				{{index+1}}.{{item.value}}
				<text class="show-status" v-if="item.show_status == 1">(公开)</text>
				<text class="show-status" v-if="item.show_status == -1">(不公开)</text>
				</view>
				<view class="content" v-if="item.type == 'username'">
					<!--叹号item.ext_sel_type 防止未设置该字段的时候 不能选择-->
					<view class="flex align-center"  v-if="(item.ext && item.ext.length > 0 && (!item.ext_sel_type || item.ext_sel_type == 1))">
						<view class="sel-username">{{showUsername[index]}}</view>
						<view class="sel-button"  @tap="showSelectFunc('show',index)">选择人员</view>
					</view>
					<input class="input-text" v-else placeholder-class="p-class"  v-model="resultData[index]"  type="text" :placeholder="'请输入'+item.value"/>
				</view>
				
				<view class="content" :class="item.type=='phone'?'flex align-center':''" v-if="item.type == 'number' || item.type == 'phone'">
					<input class="input-text" placeholder-class="p-class" v-model="resultData[index]" type="number" :placeholder="'请输入'+item.value"/>
					<button v-if="item.type == 'phone'" class='sel-button type-button' type='primary' open-type="getPhoneNumber" withCredentials="true" 
					lang="zh_CN"  @getphonenumber="getInputMobile" :data-index="index">
					    自动填入
					</button>
					<!-- <view class="sel-button" v-if="item.type == 'phone'"  @tap.stop="getInputMobile(index)">自动填入</view> -->
				</view>
				
				<view class="content" v-if="item.type == 'digit'">
					<input class="input-text" placeholder-class="p-class" v-model="resultData[index]" type="digit" :placeholder="'请输入'+item.value"/>
				</view>
				
				<view class="content" v-if="item.type == 'id_card'">
					<input class="input-text" placeholder-class="p-class" v-model="resultData[index]" type="idcard" :placeholder="'请输入'+item.value"/>
				</view>
				<view class="content" v-if="item.type == 'radio'">
					<view class="radio-0" v-for="(radioItem,radioIndex) in item.ext" :key="radioIndex"  @tap.stop="radioClick(index,radioIndex)">
						<view class="icon-left" >
							<text class="iconfont icon-danxuan1-xuanzhong " v-if="(resultData[index]) == radioIndex.toString()"></text>
							<text class="iconfont icon-danxuan1" v-else></text>
						</view>
						<view class="right-content">{{radioItem}}</view>
					</view>
				</view>
				<view class="content" v-if="item.type == 'text' || item.type == 'email' || item.type == 'chinese' ||
				item.type == 'english' || item.type == 'en_number'">
					<input class="input-text" placeholder-class="p-class" v-model="resultData[index]" type="text" :placeholder="'请输入'+item.value"/>
				</view>
				
				<view class="content" v-if="item.type == 'textarea'">
					<view class="text-area">
						<textarea class="show-textarea"  :show-confirm-bar="true" placeholder-class="p-class" :placeholder="'请输入'+item.value" 
						maxlength="-1" v-model="resultData[index]"/>
					</view>
				</view>
				
				<view class="content" v-if="item.type == 'qianming'">
					<view class="qianming" @tap="qianmingClick('show',index)">
						<view v-if="resultData[index].value == ''" class="qianming-text" >点此签名</view>
						<view v-else >
							<image class="qm-image" :src="resultData[index].value">
							<text class="iconfont icon-shanchu-mian closeempty" @tap.stop="qianmingClick('del',index)"></text>
						</view>
					</view>
					
				</view>
				
				
				<view class="content" v-if="item.type == 'checkbox'">
					<view class="radio-0 checkbox-0" v-for="(checkItem,checkIndex) in item.ext" :key="checkIndex"  @tap.stop="checkBoxClick(index,checkIndex)">
						<view class="icon-left">
							<text class="iconfont icon-xuanzhong" v-if="(resultData[index]) && (resultData[index].indexOf(checkIndex)) > -1"></text>
							<text class="iconfont icon-weixuanzhong" v-else></text>
						</view>
						<view class="right-content">{{checkItem}}</view>
					</view>
				</view>
				
				<view class="content" v-if="item.type == 'date'">
					<view class="sel-time">
						<view  @tap="DatePicker('date',index)" v-if="resultData[index] == ''">选择日期</view>
						<view  @tap="DatePicker('date',index)" v-else>{{resultData[index]}}</view>
						<text class="iconfont icon-youjiantou"></text>
					</view>
				</view>
				
				<view class="content" v-if="item.type == 'time'">
					<view class="sel-time">
						<view  @tap="DatePicker('time',index)" v-if="resultData[index] == ''">选择时间</view>
						<view  @tap="DatePicker('time',index)" v-else>{{resultData[index]}}</view>
						<text class="iconfont icon-youjiantou"></text>
					</view>
				</view>
				
				<view class="content" v-if="item.type == 'datetime'">
					<view class="sel-time">
						<view  @tap="DatePicker('datetime',index)" v-if="resultData[index] == ''">选择时间日期</view>
						<view  @tap="DatePicker('datetime',index)" v-else>{{resultData[index]}}</view>
						<text class="iconfont icon-youjiantou"></text>
					</view>
				</view>
				
				<view class="content" v-if="item.type == 'city'">
					<view class="sel-time">
						<view >
							<picker mode="region"  @change="selAreaChange" :data-index="index">
							    <view>{{resultData[index].value?resultData[index].value:'请选择'}} </view>
						    </picker>
						</view>
						<text class="iconfont icon-youjiantou"></text>
					</view>
				</view>
				
				<view class="content" v-if="item.type == 'address'">
					<view class="sel-address">
						<view class="show-address">
							{{resultData[index].address?resultData[index].address:''}}
						</view>
						<view class="change-address" @tap="chooseLocation(index)" 
							:class="!resultData[index].address || resultData[index].address==''?'':'margin-r'">
							<view v-if="!resultData[index].address || resultData[index].address == ''">选择位置</view>
							<view v-else >重新选择</view>
						</view>
					</view>
				</view>
				
				<view class="content" v-if="item.type == 'position'">
					<view class="sel-address">
						<view class="show-address">
							{{resultData[index].address?resultData[index].address:''}}
						</view>
						<view class="change-address" @tap="getLocation(index)" 
							:class="!resultData[index].address || resultData[index].address==''?'':'margin-r'">
							<view v-if="!resultData[index].address || resultData[index].address == ''">点击定位</view>
							<view v-else >重新定位</view>
						</view>
					</view>
				</view>
				
				
				<view class="content" v-if="item.type == 'image'">
					<wzf-image-upload :dataType="0"  :max="item.ext.type == 1?1:9" mediaType="image" :chooseNum="item.ext.type == 1?1:9"
					 @chooseSuccess="chooseSuccess" @imgDelete="chooseDelete" v-model="resultData[index].value" :index="index"></wzf-image-upload>
				</view>
				
				
				<view class="content" v-if="item.type == 'video'">
					<wzf-image-upload  :dataType="0" :max="1" mediaType="video" name="file" :chooseNum="1" :index="index"
					@chooseSuccess="chooseSuccess" @imgDelete="chooseDelete" v-model="resultData[index].value" 
					></wzf-image-upload> 
				</view>
				
				<view class="content" v-if="item.type == 'file'">
					<view class="docx">
						<view class="doc_title" v-if="resultData[index].value.name">{{resultData[index].value.name}}</view>
						<!-- #ifdef MP-WEIXIN -->
						<view class="sel-docx" @tap="selDocxFromWx(index)">从微信会话中选择</view>
						<!-- #endif -->
					</view>
				</view>
				
				
			</view>
		</view>
		
		<mx-date-picker :show="mxDatePicker.showPicker" :type="mxDatePicker.type" :value="mxDatePicker.value" :show-tips="true" 
		:show-seconds="true" @confirm="DatePickerEnd" @cancel="DatePickerEnd" />
		<znxd-sxqm :show.sync="qmData.showSxqm" ref="sxqm" imgtype="base64" @success="sxqmSuccess"></znxd-sxqm>
		<!-- 人员选择框 -->
		<view class="add-check_s" @touchmove.stop.prevent="moveHandle"  v-if="showSelect.status == true">
			<view class="add-check-title">请选择<text class="mast-text">深色背景代表已被使用，无法选择</text></view>
			<view>
				<scroll-view scroll-y="true" class="scroll-y">
					<view class="flex align-center flex-wrap">
						<view  v-for="(item,index) in showSelect.canSelList" :key="index" class="scroll-view-item">
							<view  class="scroll-view-item-list " :class="showSelect.selIndex == index?'scroll-item-active':''"
							v-if="item.status == 1" @tap.stop="showSelectFunc('sel',index)">{{item.name}}</view>
							<view  class="scroll-view-item-list scroll-item-disabled" v-else>{{item.name}}</view>
						</view>
						
					</view>
					
				</scroll-view>
			</view>
			 <view class="add-check-button">
				 <view class="add-check-cls add-check-cancel fl" @tap="showSelectFunc('cancel')">取  消</view>
				 <view class="add-check-cls add-check-confirm fl" @tap="showSelectFunc('confirm')">确  认</view>
			 </view>
		</view>
	</view>
</template>

<script>
	import wzfImageUpload from '@/components/wzf-image-upload/wzf-image-upload.vue';
	import MxDatePicker from "@/components/mx-datepicker/mx-datepicker.vue";
	import znxdSxqm from "@/components/znxd-sxqm/znxd-sxqm.vue";
	import Upload from "@/utils/fileupload/upload";
	export default {
		name:'preview-form',
		components:{
			wzfImageUpload,
			MxDatePicker,
			znxdSxqm
		},
		data() {
			return {
				//显示可选择的列表
				showSelect:{
					canSelList:[],
					status:false,
					listIndex:-1,
					selIndex:-1
				},
				imageDataType: [
					//'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-f184e7c3-1912-41b2-b81f-435d1b37c7b4/1ae87107-2943-4ba6-be2b-390ca27c6260.png'
				],
				videoData:[],
				//日期时间选择数据
				mxDatePicker:{
					showPicker: false,
					type: '',
					value: '',
					index:-1,
				},
				qmData:{
					index:-1,
					showSxqm:false
				},
				resultData:[],
				uploadFileListLog:{}, //记录上传的文件资源
				showUsername:[],
			}
		},
		props:{
			dataList:{
				type:Array,
				default:[]
			},
			default_user_index:{
				type:[Number,String],
				default:-1
			}
		},
		mounted:function(){
			if(this.resultData.length < 1)
			{
				this.initResultData();
			}
			
		},
		methods: {
			
			//操作结果 反馈给父级
			resultDataFunc(){
				this.$emit('resultChange',this.resultData);
			},
			//获取微信手机号
			getInputMobile(e){
				var that = this;
				var index  = e.target.dataset.index;
				if(index < 0)
				{
					that.$api.msg('无法设置');return ;
				}
				var info = e.detail;
				if(info.errMsg == 'getPhoneNumber:ok')
				{
					if(!info.code)
					{
						that.$api.msg('微信版本过低，无法获取');return ;
					}
					that.$api.getPhoneMobile({
						code:info.code
					},function(res){
						if(res.phone)
						{
							that.resultData[index] = res.phone;
							that.$forceUpdate(); 
						}
					});
				}
				 
			},
			//单选点击事件
			radioClick(index,c_index)
			{
				this.resultData[index] = c_index;
				this.$forceUpdate(); //强制更新某个值
			},
			checkBoxClick(index,c_index)
			{
				var value = this.resultData[index];
				var key = value.indexOf(c_index);
				if(key > -1)
				{
					value.splice(key,1);
				}else{
					value.push(c_index)
				}
				this.resultData[index] = value;
				this.$forceUpdate(); //强制更新某个值
			},
			//选择项
			showSelectFunc(type,index)
			{
				var data = this.dataList;
				if(type == 'show')
				{
					this.showSelect.listIndex = index;
					this.showSelect.status = true;
					var ext = data[index].ext;
					var extUser = data[index].extUser?data[index].extUser:{};
					var resultDataIndexValue = (this.resultData[index].toString() == '')?-1:this.resultData[index];
					if(resultDataIndexValue >= 0)
					{
						this.showSelect.selIndex = resultDataIndexValue;
					}else{
						this.showSelect.selIndex = -1;
					}
					var extList = [];
					for(var i=0;i<ext.length;i++)
					{
						var status = (extUser[i])?-1:1;
						extList.push({
							name:ext[i],
							status:status
						})
					}
					this.showSelect.canSelList = extList;
				}else if(type == 'sel')
				{
					var nowIndex = this.showSelect.selIndex;
					this.showSelect.selIndex = (nowIndex == index)?-1:index;
				}else if(type == 'cancel')
				{
					this.showSelect.status = false;
				}else if(type == 'confirm')
				{
					if(this.showSelect.selIndex == -1)
					{
						var username = '';
					}else{
						let info = this.showSelect.canSelList[this.showSelect.selIndex];
						var username = info.name;
					}
					this.showUsername[this.showSelect.listIndex] = username;
					this.showSelect.status = false;
					this.resultData[this.showSelect.listIndex] = this.showSelect.selIndex;
					this.resultDataFunc();
				}
			},
			//点击签名事件
			qianmingClick(type,index)
			{
				console.log(type,index)
				if(type == 'show')
				{
					this.qmData.index = index;
					this.$refs.sxqm.saveSignImage(this.resultData[index].value);
					this.qmData.showSxqm = true;
				}else if(type == 'del')
				{
					this.resultData[index].value = '';
					this.qmData.index = -1;
					this.qmData.showSxqm = false;
					this.resultDataFunc();
					this.$forceUpdate();
				}
			},
			//签名手写成功之后的回调
			sxqmSuccess(e){
				//console.log(e.url)
				if(this.qmData.index > -1)
				{
					this.resultData[this.qmData.index].value = e.url;
				}
				this.qmData.showSxqm = false;
			},
			getLocation(index){
				var that = this;
				that.$api.loadingMsg('正在定位');
				that.$api.getLocation(function(e){
					console.log("定位结果"+JSON.stringify(e))
					//uni.hideLoading();
					if(e.address)
					{
						that.resultData[index] = {
							address:(e.address?e.address:''),
							lat:e.lat,
							lng:e.lng,
							map_type:'tianditu'
						};
						that.$forceUpdate()
					}
				},function(err){
					console.log("定位结果"+JSON.stringify(err))
				});
			},
			chooseLocation(index){
				var that = this;
				that.$api.chooseLocation(function(e){
					if(e.address)
					{
						that.resultData[index] = {
							address:(e.address?e.address:'')+(e.name?e.name:''),
							lat:e.latitude,
							lng:e.longitude,
							map_type:'tencent'
						};
						that.$forceUpdate()
					}
				});
			},
			selAreaChange(e){
				try{
					var index = e.currentTarget.dataset.index;
				}catch{
					var index = -1;
				}
				if(index == -1)
				{
					this.$api.msg('选择失败');
					return;
				}
				var detail = e.detail;
				this.resultData[index].code = detail.code.join(',');
				this.resultData[index].value = detail.value.join(',');
				this.$forceUpdate();
			},
			DatePicker(type,index){//显示
				this.mxDatePicker.index = index;
				this.mxDatePicker.type = type; 
				this.mxDatePicker.showPicker = true;
				this.mxDatePicker.value = this.resultData[index];
				//this.mxDatePicker.value  = '';
				this.$forceUpdate();
			},
			DatePickerEnd(e) {//选择
				this.mxDatePicker.showPicker = false;
				if(e) {
					this.resultData[this.mxDatePicker.index] = e.value;
					this.$forceUpdate();
				}
			},
			//微信小程序选择文档
			selDocxFromWx(index){
				//console.log(index)
				var _this = this;
				wx.chooseMessageFile({
					count: 1,
					type: 'file',
					extension:['docx','doc','xls','xlsx','ppt','pptx','pdf'],
					success(res) {
						//console.log(res)
						if(res.tempFiles.length > 0)
						{
							_this.resultData[index].value.name =  res.tempFiles[0].name;
							_this.resultData[index].value.path =  res.tempFiles[0].path;
							_this.$forceUpdate();
							//_this.sel_docx = res.tempFiles[0].path;
						}
					}
				})
			},
			//选择图片视频之类的
			chooseSuccess(tempFilePaths, type,index) {
				var thisDatas = []
				tempFilePaths.forEach(item => {
					thisDatas.push(item)
				})
				//console.log('thisDatas', thisDatas)
				
				this.resultData[index].value.push(...thisDatas)
				this.$forceUpdate();
				//this.imageDataType.push(...thisDatas)
			},
			//删除回调
			chooseDelete(e){
				console.log(e,'chooseDelete');  //a
				this.resultData[e.index].value = e.tempFilePaths;
				this.$forceUpdate();
			},
			//初始化提交结果
			initResultData(){
				var _this = this;
				var dataList = _this.dataList;
				if(dataList.length > 0)
				{
					dataList.forEach(function(item,index){
						if(item.type == 'qianming' || item.type == 'image' || item.type == 'video' || item.type == 'file')
						{
							var value = (item.type == 'image' || item.type == 'video')?[]:'';
							if(item.type == 'file')
							{
								value = {
									name:'',
									path:'',
									qnPath:''
								};
								_this.resultData[index] = {
									type:item.type,
									value:value,
								};
							}else{
								_this.resultData[index] = {
									type:item.type,
									value:value,
									qnValue:value
								};
							}
							
						}else if(item.type == 'checkbox'){
							_this.resultData[index] = [];
						}else if(item.type == 'city'){
							_this.resultData[index] = {
								code:'',
								value:''
							};
						}else if(item.type == 'username'){
							//追加默认显示
							if(_this.default_user_index > -1)
							{
								if(item.ext && item.ext.length > 0)
								{
									var name = item.ext[_this.default_user_index]?item.ext[_this.default_user_index]:'';
									if(!item.ext_sel_type || item.ext_sel_type == 1)
									{
										_this.resultData[index] = _this.default_user_index;
										_this.showUsername[index] = name;
									}else{
										//如果是2的话  代表需要用户手动填写  因此直接展示用户姓名
										_this.resultData[index] = name;
									}
									
								}else{
									_this.resultData[index] = '';
								}
							}else{
								_this.resultData[index] = '';
							}
						}else{
							_this.resultData[index] = '';
						}
					})
					_this.$forceUpdate(); //强制更新某个值
				}
			},
			//编辑的时候，从已保存数据修改值
			saveInitResultData(saveData){
				var _this = this;
				var dataList = _this.dataList;
				//初始化异常参数
				var errorImage = this.$api.getSystemConfig('errorImage');
				var errorImageBse = this.$api.getSystemConfig('errorImageBse');
				for(var key in errorImage)
				{
					var md5Name = _this.$api.getMd5Name(errorImage[key],false);
					_this.uploadFileListLog[md5Name] = errorImageBse[key];
				}
				//初始化显示列表
				if(dataList.length > 0)
				{
					dataList.forEach(function(item,index){
						var saveInfo = saveData[index];
						if(item.type == 'username')
						{
							if(_this.default_user_index > -1)
							{
								//如果是从打卡页面选中进来的 那么不应该设置默认值  默认应该是用户选中的这个
								if(item.ext && item.ext.length > 0)
								{
									var name = item.ext[_this.default_user_index]?item.ext[_this.default_user_index]:'';
									if(!item.ext_sel_type || item.ext_sel_type == 1)
									{
										_this.resultData[index] = _this.default_user_index;
										_this.showUsername[index] = name;
									}else{
										//如果是2的话  代表需要用户手动填写  因此直接展示用户姓名
										_this.resultData[index] = name;
									}
								}else{
									_this.resultData[index] = ''; 
								}
							}else{
								if(saveInfo.type == 'sel')
								{
									if(item.extUser && item.extUser[saveInfo.sel_key])
									{
										item.extUser[saveInfo.sel_key] = '';//当为edit的时候 代表是他本人选择的 把他本人的清空 防止这个人填写不上
									}
									var name = item.ext[saveInfo.sel_key]?item.ext[saveInfo.sel_key]:'';
									if(!item.ext_sel_type || item.ext_sel_type == 1)
									{
										_this.resultData[index] = saveInfo.sel_key;
										_this.showUsername[index] = name;
									}else{
										//如果是2的话  代表需要用户手动填写  因此直接展示用户姓名
										_this.resultData[index] = name;
									}
								}else if(saveInfo.type == 'input'){
									_this.resultData[index] = saveInfo.content;
								}
							}
						}
						else if(item.type == 'qianming' || item.type == 'image' || item.type == 'video' || item.type == 'file')
						{
							var value = ''; //要显示的资源地址 后续包含cdnurl
							if(item.type == 'qianming')
							{
								var value = saveInfo.qnValue?saveInfo.qnValue:'';
								if(value)
								{
									var md5Name = _this.$api.getMd5Name(value,false);
									_this.uploadFileListLog[md5Name] = saveInfo.value;
								}
							}else if(item.type == 'image' || item.type == 'video'){
								var value = saveInfo.qnValue?saveInfo.qnValue:[];
								if(value.length > 0)
								{
									for(var i=0;i<value.length;i++)
									{
										var md5Name = _this.$api.getMd5Name(value[i],false);
										_this.uploadFileListLog[md5Name] = saveInfo.value[i];
									}
								}
							}else if(item.type == 'file'){
								var value = {
									name:saveInfo.name?saveInfo.name:'',
									path:saveInfo.qnPath?saveInfo.qnPath:'',
									qnPath:''
								};
								if(saveInfo.qnPath)
								{
									var md5Name = _this.$api.getMd5Name(saveInfo.qnPath,false);
									_this.uploadFileListLog[md5Name] = saveInfo.path;
								}
								
							}
							if(item.type == 'file')
							{
							
								_this.resultData[index] = {
									type:item.type,
									value:value,
								};
							}else{
								_this.resultData[index] = {
									type:item.type,
									value:value,
									qnValue:value
								};
							}
							
						}else if(item.type == 'checkbox'){
							if(saveInfo && saveInfo.length > 0)
							{
								_this.resultData[index] = saveInfo;
							}else{
								_this.resultData[index] = [];
							}
						}else if(item.type == 'city'){
							if(saveInfo.code)
							{
								_this.resultData[index] = {
									code:saveInfo.code,
									value:saveInfo.value
								};
							}else{
								_this.resultData[index] = {
									code:'',
									value:''
								};
							}
							
						}else{
							_this.resultData[index] = saveInfo
						}
					})
					//console.log('修改后resultData',_this.resultData)
					//console.log('_this.uploadFileListLog',_this.uploadFileListLog)
				}
				_this.$forceUpdate(); //强制更新某个值
			},
			//获取最终的表单数据
			async getFormData(){
				var _this = this;
				var checkRes = false,uploadRes = false;
				var checkRes = _this.checkFormData();
				if(checkRes == false)
				{
					return [];
				}
				var uploadRes = await _this.uploadFile(); //上传文件
				console.log('uploadRes',uploadRes);
				if(uploadRes == false)
				{
					return [];
				}
				var dataList = _this.dataList;
				var resultData = _this.resultData;
				//console.log('resultData',resultData)
				var uploadFileListLog = _this.uploadFileListLog;
				//console.log('uploadFileListLog',uploadFileListLog)
				var haveError = false;
				for(var i=0;i<dataList.length;i++)
				{
					var item = dataList[i];
					if(item.type == 'qianming')
					{
						var qmInfo = resultData[i].value?resultData[i].value:'';
						if(qmInfo)
						{
							var md5Name = _this.$api.getMd5Name(qmInfo,false);
							//console.log('md5Name',md5Name);
							if(uploadFileListLog[md5Name])
							{
								resultData[i].qnValue = uploadFileListLog[md5Name];
							}else{
								_this.$api.msg('第'+(i+1)+'个选项，手写签名文件未上传');
								haveError = true;
								break ;
								//_this.$api.msg()
							}
						}else{
							resultData[i].qnValue = '';
						}
					}
					else if(item.type == 'image' || item.type == 'video')
					{
						var valueList = resultData[i].value?resultData[i].value:[];
						var uploadList = [];
						if(valueList.length > 0)
						{
							var uploadHaveError = false;
							for(var y=0;y<valueList.length;y++)
							{
								var md5Name = _this.$api.getMd5Name(valueList[y],false);
								//console.log('md5Name',md5Name);
								if(uploadFileListLog[md5Name])
								{
									uploadList.push(uploadFileListLog[md5Name])
								}else{
									uploadHaveError = true;
									var text = (item.type == 'image')?'图片':'视频';
									this.$api.msg('第'+(i+1)+'个选项，第'+(y+1)+'个'+text+'未上传');
									break;
								}
							}
							if(uploadHaveError == true)
							{
								haveError = true; //数据错误 直接终止
								break;
							}
						}
						resultData[i].qnValue = uploadList;
					}
					else if(item.type == 'file')
					{
						var fileInfo = resultData[i].value.path?resultData[i].value.path:'';
						if(fileInfo)
						{
							var md5Name = _this.$api.getMd5Name(fileInfo,false);
							//console.log('md5Name',md5Name);
							if(uploadFileListLog[md5Name])
							{
								resultData[i].value.qnPath = uploadFileListLog[md5Name];
							}else{
								_this.$api.msg('第'+(i+1)+'个选项，选择的文件未上传');
								haveError = true;
								break ;
							}
							
						}else{
							resultData[i].value.qnPath  = '';
						}
					}
				}
				if(haveError)
				{
					return [];
				}
				_this.resultData = resultData;
				return resultData;
			},
			//检测表单里面的填写内容
			checkFormData(){
				var _this = this;
				var dataList = _this.dataList;
				var resultData = _this.resultData;
				console.log('resultData',resultData);
				var errorText = '';
				for(var i=0;i<dataList.length;i++)
				{
					var item = dataList[i];
					if(item.type == 'phone' && resultData[i] != '' && !_this.$api.isPhoneNumber(resultData[i]))
					{
						errorText = '第'+(i+1)+'项请填写正确的手机号'; //如果填写了手机号 那么不管是不是必须填写 都需要验证
						break;
					}else if(item.type == 'email' && resultData[i] != '' && !_this.$api.checkEmail(resultData[i]))
					{
						errorText = '第'+(i+1)+'项请填写正确的邮箱'; //如果填写了手机号 那么不管是不是必须填写 都需要验证
						break;
					}else if(item.type == 'chinese' && resultData[i] != '' && !_this.$api.checkChinese(resultData[i]))
					{
						errorText = '第'+(i+1)+'项只能填写汉字'; //如果填写了手机号 那么不管是不是必须填写 都需要验证
						break;
					}else if(item.type == 'english' && resultData[i] != '' && !_this.$api.checkEnglish(resultData[i]))
					{
						errorText = '第'+(i+1)+'项只能填写英文字母'; //如果填写了手机号 那么不管是不是必须填写 都需要验证
						break;
					}else if(item.type == 'en_number' && resultData[i] != '' && !_this.$api.checkEnNumber(resultData[i]))
					{
						errorText = '第'+(i+1)+'项只能填写英文字母和数字'; //如果填写了手机号 那么不管是不是必须填写 都需要验证
						break;
					}else if(item.type == 'id_card' && resultData[i] != '' && !_this.$api.checkCard(resultData[i]))
					{
						errorText = '第'+(i+1)+'项请填写正确的身份证号'; //如果填写了手机号 那么不管是不是必须填写 都需要验证
						break;
					}else if(item.type == 'username' && resultData[i] != '')
					{
						if(item.ext_sel_type && item.ext_sel_type == 2)
						{
							var indexOf = item.ext.indexOf(resultData[i].toString());
							if(item.ext.indexOf(resultData[i].toString()) == -1)
							{
								errorText = '第'+(i+1)+'项填写内容不在预设名单中，请联系发布者确认！';
								break;
							}
							if(item.extUser && item.extUser[indexOf])
							{
								errorText = '第'+(i+1)+'项填写的内容“'+resultData[i]+'”已被占用！';
								break;
							}
						}
					}
					if(item.must_status == 1)
					{
						if(typeof resultData[i] == 'number')
						{
							resultData[i] = resultData[i].toString();
						}
						//必须填写
						if(item.type == 'username')
						{
							if(item.ext && item.ext.length > 0)
							{
								if(item.ext_sel_type && item.ext_sel_type == 2)
								{
									if(resultData[i] == '')
									{
										errorText = '请填写第'+(i+1)+'项内容';
										break;
									}
									if(item.ext.indexOf(resultData[i].toString()) == -1)
									{
										errorText = '第'+(i+1)+'项填写内容不在预设名单中，请联系发布者确认！';
										break;
									}
									if(item.extUser && item.extUser[indexOf])
									{
										errorText = '第'+(i+1)+'项填写的内容“'+resultData[i]+'”已被占用！';
										break;
									}
								}else{
									if(resultData[i] == '' || resultData[i] == '-1')
									{
										errorText = '请选择第'+(i+1)+'项内容';
										break;
									}
								}
								
							}else{
								if(resultData[i] == '')
								{
									errorText = '请填写第'+(i+1)+'项内容';
									break;
								}
							}
						}
						else if(item.type == 'radio' && resultData[i] == '')
						{
							errorText = '请选择第'+(i+1)+'项选项';
							break;
						}
						else if(item.type == 'qianming' && resultData[i].value == '')
						{
							errorText = '第'+(i+1)+'项请完成签名';
							break;
						}
						else if((item.type == 'image' || item.type == 'video') && resultData[i].value.length < 1)
						{
							var text = (item.type == 'image')?'图片':'视频';
							errorText = '第'+(i+1)+'项请上传'+text;
							break;
						}
						else if(item.type == 'file' && resultData[i].value.path == '')
						{
							errorText = '第'+(i+1)+'项请上传文件';
							break;
						}
						else if(item.type == 'checkbox' && resultData[i].length < 1)
						{
							errorText = '请选择第'+(i+1)+'项选项';
							break;
						}
						else if(item.type == 'city' && (resultData[i].code == '' || resultData[i].value == ''))
						{
							errorText = '请选择第'+(i+1)+'项城市';
							break;
						}
						else if(resultData[i] == '')//else if(resultData[i] == '' || resultData[i] == '-1')
						{
							errorText = '请填写第'+(i+1)+'项内容';
							break;
						}
					}
				}
				//console.log(this.resultData)
				if(errorText)
				{
					_this.$api.msg(errorText);
					return false;
				}
				return true;
			},
			//上传文档里面的内容
			async uploadFile(){
				var that = this;
				var resData = that.resultData;
				//console.log('uploadFileListLog',this.uploadFileListLog)
				try{
					if(resData.length > 0)
					{
						var uploadStatus = true;
						for(var i=0;i<resData.length;i++)
						{
							var item = resData[i];
							/* if(!item || item == '' || typeof item.type == 'undefined')
							{
								continue;
							} */
							if(item.type == 'image')
							{
								var imageList = item.value;
								var uploadStatus = await  that.uploadImgList(imageList,i);
								
							}else if(item.type == 'video')
							{
								var videoList = item.value;
								var uploadStatus = await that.uploadVideoList(videoList,i);
							}else if(item.type == 'file')
							{
								var fileInfo = item.value.path?item.value.path:'';
								var uploadStatus = await that.uploadFileInfo(fileInfo,i);
							}else if(item.type == 'qianming')
							{
								var qmInfo = item.value?item.value:'';
								var uploadStatus = await that.uploadQmInfo(qmInfo,i);
							}
							if(uploadStatus == false)
							{
								break;
							}
						}
					}
				}catch(e){
					console.log(e)
					that.$api.msg('捕获异常:上传文件失败');
					uni.hideLoading();
					return false;
				}
				if(uploadStatus == false)
				{
					return false;
				}
				return true;
			},
			async uploadQmInfo(qmInfo,itemIndex){
				qmInfo = qmInfo?qmInfo:'';
				var uploadStatus = true;
				if(qmInfo)
				{
					var md5Name = this.$api.getMd5Name(qmInfo,false);
					if(!this.uploadFileListLog[md5Name])
					{
						var fileRes = await Upload.uploadImageToQiniuH5([
							{
								path:qmInfo
							}
						])
						uni.hideLoading()
						if(fileRes.list && fileRes.list.length > 0)
						{
							this.uploadFileListLog[md5Name] = fileRes.list[0];
						}else{
							uploadStatus = false;
							this.$api.msg('第'+(itemIndex+1)+'个选项，手写签名上传失败');
						}
						
					}
				}
				return uploadStatus;
			},
			async uploadFileInfo(fileInfo,itemIndex){
				
				fileInfo = fileInfo?fileInfo:'';
				var uploadStatus = true;
				if(fileInfo)
				{
					var md5Name = this.$api.getMd5Name(fileInfo,false);
					if(!this.uploadFileListLog[md5Name])
					{
						var fileRes = await Upload.uploadFileToQiniu([
							{
								name:fileInfo,
								path:fileInfo
							}
						])
						uni.hideLoading()
						if(fileRes.list && fileRes.list.length > 0)
						{
							this.uploadFileListLog[md5Name] = fileRes.list[0];
						}else{
							uploadStatus = false;
							this.$api.msg('第'+(itemIndex+1)+'个选项，文件上传失败');
						}
						
					}
				}
				return uploadStatus;
			},
			async uploadVideoList(videoList,itemIndex){
				videoList = videoList?videoList:[];
				var uploadStatus = true;
				if(videoList.length > 0)
				{
					var newVideoArr = [];
					for(var i=0;i<videoList.length;i++)
					{
						var md5Name = this.$api.getMd5Name(videoList[i],false);
						if(!this.uploadFileListLog[md5Name])
						{
							//上传视频
							var videoRes = await Upload.uploadVideoToQiniu([
								{
									tempFile:{
										name:videoList[i],
									},
									tempFilePath:videoList[i]
								}
							])
							if(videoRes.list && videoRes.list.length > 0)
							{
								this.uploadFileListLog[md5Name] = videoRes.list[0];
							}else{
								uploadStatus = false;
								this.$api.msg('第'+(itemIndex+1)+'个选项，第'+(i+1)+'个视频上传失败');
								break;
							}
						}
					}
					uni.hideLoading();
				}
				return uploadStatus;
			},
			async uploadImgList(imageList,itemIndex){
				
				imageList = imageList?imageList:[];
				var uploadStatus = true;
				if(imageList.length > 0)
				{
					var newIamgeArr = [];
					for(var i=0;i<imageList.length;i++)
					{
						console.log(imageList[i],this.uploadFileListLog)//
						var md5Name = this.$api.getMd5Name(imageList[i],false);
						if(!this.uploadFileListLog[md5Name])
						{
							//上传图片
							var imgRes = await Upload.uploadImageToQiniuH5([
								{
									path:imageList[i]
								}
							],0)
							if(imgRes.list && imgRes.list.length > 0)
							{
								this.uploadFileListLog[md5Name] = imgRes.list[0];
							}else{
								uploadStatus = false;
								this.$api.msg('第'+(itemIndex+1)+'个选项，第'+(i+1)+'张照片上传失败');
								break;
							}
						}
					}
					uni.hideLoading();
				}
				return uploadStatus;
			},
			
			
		},
		
	}
</script>

<style lang="scss"> 
	.show-status{
		color: #999999;
		margin-left: 10rpx;
	}
	.mast-text{
		color: red;
		font-size: 26rpx;
	}
	
	.preview-body{
		background-color: #ffffff;
		width: 94%;
		margin: 3%;
		border-radius: 20rpx;
		.p-class{
			font-size: 24rpx;
		}
		
		.list{
			border-bottom: 2rpx solid #eee;
			padding: 0rpx 20rpx;
			.content{
				height: auto;
				word-break:break-all;
				padding-bottom: 10rpx;
				.sel-username{
					width: 600rpx;
				}
				.sel-button{
					background-color: $uni-btn-color;
					width: 150rpx;
					height: 60rpx;
					line-height: 60rpx;
					text-align: center;
					color: #ffffff;
					border-radius: 15rpx;
					font-size: 24rpx;
				}
				.type-button{
					width: 160rpx;
				}
				.text-area{
					.show-textarea{
						width: 100%;
						border: 2rpx solid #eee;
						border-radius: 10rpx;
						padding: 20rpx 10rpx;
					}
				}
				.qianming{
					width: 100%;
					height: 300rpx;
					background: #F4F4F4;
					border-radius: 10rpx;
					position: relative;
					.qianming-text{
						position: absolute;
						width: 100%;
						text-align: center;
						top: 140rpx;
						letter-spacing: 6rpx;
						font-size: 28rpx;
					}
					.qm-image{
						width: 100%;
						height: 300rpx;
					}
					.closeempty{
						position: absolute;
						font-size: 44rpx;
						top: 4px;
						right: 10rpx;
					}
				}
				.sel-address{
					font-size: 26rpx;
					color: #807777;
					display: flex;
					align-items: center;
					.show-address{
						max-width: 80%;
					}
					.change-address{
						background-color: $uni-btn-color;
						width: 150rpx;
						height: 60rpx;
						line-height: 60rpx;
						text-align: center;
						color: #ffffff;
						border-radius: 15rpx;
						font-size: 24rpx;
					}
					.margin-r{
						margin-left: 10rpx;
					}
				}
				.sel-time{
					height: 80rpx;
					line-height: 80rpx;
					font-size: 26rpx;
					color: #807777;
					position: relative;
					.iconfont{
						position: absolute;
						right: 0;
						top: 0;
					}
				}
				.docx{
					.doc_title{
						color: #3D5B7D;
						margin-bottom: 15rpx;
					}
					.sel-docx{
						background-color: $uni-btn-color;
						width: 300rpx;
						height: 60rpx;
						line-height: 60rpx;
						text-align: center;
						color: #ffffff;
						border-radius: 15rpx;
						font-size: 26rpx;
					}
				}
				
				.radio-0{
					display: flex;
					align-items: center;
					min-height: 60rpx;
					.iconfont{
						font-size: 42rpx;
						color: $uni-btn-color;
					}
					.icon-left{
						margin-right: 10rpx;
					}
					.right-content{
						
					}
				}
				.checkbox-0{
					.iconfont{
						font-size: 30rpx;
						color: $uni-btn-color;
					}
				}
				.input-text{
					height: 60rpx;
					min-width: 510rpx;
				}
				
			}
			.title{
				height: 80rpx;
				line-height: 80rpx;
				overflow: hidden;
				font-size: 28rpx;
			}
		}
	}
	.add-check_s{
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background: #FFFFFF;
		z-index: 999;
		.add-check-title{
			height: 50rpx;
			line-height: 50rpx;
			padding-left: 30rpx;
			margin-top: 30rpx;
		}
		.scroll-y{
			height: 900rpx;
			border: 2rpx solid #eee;
			width: 96%;
			margin: 0rpx 3%;
			border-radius: 10rpx;
			padding: 20rpx;
			.scroll-view-item{
				width: 25%;
				.scroll-view-item-list{
					width: 90%;
					//background: #F4F4F4;
					margin: auto;
					margin-bottom: 16rpx;
					height: 60rpx;
					text-align: center;
					line-height: 60rpx;
					border-radius: 20rpx;
					font-size: 24rpx;
					overflow: hidden;
					color: #888888;
					border: 2rpx solid #999999;
				}
				.scroll-item-active{
					background: #89a77c;
					//background: #F4F4F4;
					color: #fff;
				}
				.scroll-item-disabled{
					background: #e0d6d6;
					color: #fff;
				}
			}
		}
		.add-check-button{
			position: absolute;
			left: 0;
			bottom: 100rpx;
			width: 100%;
			.add-check-cls{
				width: 220rpx;
				text-align: center;
				height: 70rpx;
				border-radius: 26rpx;
				line-height: 71rpx;
			}
			.add-check-cancel{
				border: 2rpx solid #8B988E;
				color: #8B988E;
				margin-left: 140rpx;
				margin-right: 50rpx;
			}
			.add-check-confirm{
				background-color: #61B080;
				color: #FFFFFF;
			}
		}
	}
</style>
